home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / !Interfaces / Universal Interfaces 2.0a1 / CIncludes / MIDI.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-17  |  9.9 KB  |  273 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        MIDI.h
  3.  
  4.      Copyright:    © 1984-1994 by Apple Computer, Inc.
  5.                  All rights reserved.
  6.  
  7.      Version:    Universal Interfaces 2.0a1.  ETO #15, MPW prerelease.  Sunday, July 17, 1994. 
  8.  
  9.      Bugs?:        If you find a problem with this file, send the file and version
  10.                  information (from above) and the problem description to:
  11.  
  12.                      Internet:    apple.bugs@applelink.apple.com
  13.                      AppleLink:    APPLE.BUGS
  14.  
  15. */
  16.  
  17. #ifndef __MIDI__
  18. #define __MIDI__
  19.  
  20.  
  21. #ifndef __ERRORS__
  22. #include <Errors.h>
  23. #endif
  24. /*    #include <ConditionalMacros.h>                                */
  25.  
  26. #ifndef __TYPES__
  27. #include <Types.h>
  28. #endif
  29.  
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33.  
  34. #if GENERATINGPOWERPC
  35. #pragma options align=mac68k
  36. #endif
  37.  
  38. #ifdef __CFM68K__
  39. #pragma lib_export on
  40. #endif
  41.  
  42.  
  43. enum {
  44.     midiToolNum                    = 4,                            /*tool number of MIDI Manager for SndDispVersion call*/
  45.     midiMaxNameLen                = 31,                            /*maximum number of characters in port and client names*/
  46. /* Time formats */
  47.     midiFormatMSec                = 0,                            /*milliseconds*/
  48.     midiFormatBeats                = 1,                            /*beats*/
  49.     midiFormat24fpsBit            = 2,                            /*24 frames/sec.*/
  50.     midiFormat25fpsBit            = 3,                            /*25 frames/sec.*/
  51.     midiFormat30fpsDBit            = 4,                            /*30 frames/sec. drop-frame*/
  52.     midiFormat30fpsBit            = 5,                            /*30 frames/sec.*/
  53.     midiFormat24fpsQF            = 6,                            /*24 frames/sec. longInt format */
  54.     midiFormat25fpsQF            = 7,                            /*25 frames/sec. longInt format */
  55.     midiFormat30fpsDQF            = 8,                            /*30 frames/sec. drop-frame longInt format */
  56.     midiFormat30fpsQF            = 9,                            /*30 frames/sec. longInt format */
  57.     midiInternalSync            = 0,                            /*internal sync*/
  58.     midiExternalSync            = 1,                            /*external sync*/
  59. /* Port types*/
  60.     midiPortTypeTime            = 0,                            /*time port*/
  61.     midiPortTypeInput            = 1,                            /*input port*/
  62.     midiPortTypeOutput            = 2,                            /*output port*/
  63.     midiPortTypeTimeInv            = 3,                            /*invisible time port*/
  64. /* OffsetTimes  */
  65.     midiGetEverything            = 0x7FFFFFFF,                    /*get all packets, regardless of time stamps*/
  66.     midiGetNothing                = 0x80000000L,                    /*get no packets, regardless of time stamps*/
  67.     midiGetCurrent                = 0x00000000                    /*get current packets only*/
  68. };
  69.  
  70. enum {
  71. /*    MIDI data and messages are passed in MIDIPacket records (see below).
  72.     The first byte of every MIDIPacket contains a set of flags
  73.    
  74.     bits 0-1    00 = new MIDIPacket, not continued
  75.                      01 = begining of continued MIDIPacket
  76.                      10 = end of continued MIDIPacket
  77.                      11 = continuation
  78.     bits 2-3     reserved
  79.   
  80.     bits 4-6      000 = packet contains MIDI data
  81.    
  82.                   001 = packet contains MIDI Manager message
  83.    
  84.     bit 7         0 = MIDIPacket has valid stamp
  85.                   1 = stamp with current clock 
  86. */
  87.     midiContMask                = 0x03,
  88.     midiNoCont                    = 0x00,
  89.     midiStartCont                = 0x01,
  90.     midiMidCont                    = 0x03,
  91.     midiEndCont                    = 0x02,
  92.     midiTypeMask                = 0x70,
  93.     midiMsgType                    = 0x00,
  94.     midiMgrType                    = 0x10,
  95.     midiTimeStampMask            = 0x80,
  96.     midiTimeStampCurrent        = 0x80,
  97.     midiTimeStampValid            = 0x00,
  98. /*    MIDI Manager MIDIPacket command words (the first word in the data field
  99.     for midiMgrType messages) */
  100.     midiOverflowErr                = 0x0001,
  101.     midiSCCErr                    = 0x0002,
  102.     midiPacketErr                = 0x0003,
  103.     midiMaxErr                    = 0x00FF,                        /*all command words less than this value  are error indicators*/
  104. /* Valid results to be returned by readHooks */
  105.     midiKeepPacket                = 0,
  106.     midiMorePacket                = 1,
  107.     midiNoMorePacket            = 2,
  108. /*     Driver calls: */
  109.     midiOpenDriver                = 1,
  110.     midiCloseDriver                = 2
  111. };
  112.  
  113. struct MIDIPacket {
  114.     UInt8                            flags;
  115.     UInt8                            len;
  116.     long                            tStamp;
  117.     UInt8                            data[249];
  118. };
  119. typedef struct MIDIPacket MIDIPacket;
  120.  
  121. typedef MIDIPacket *MIDIPacketPtr;
  122.  
  123. struct MIDIClkInfo {
  124.     short                            sync;                        /*synchronization external/internal*/
  125.     long                            curTime;                    /*current value of port's clock*/
  126.     short                            format;                        /*time code format*/
  127. };
  128. typedef struct MIDIClkInfo MIDIClkInfo;
  129.  
  130. struct MIDIIDRec {
  131.     OSType                            clientID;
  132.     OSType                            portID;
  133. };
  134. typedef struct MIDIIDRec MIDIIDRec;
  135.  
  136. struct MIDIPortInfo {
  137.     short                            portType;                    /*type of port*/
  138.     MIDIIDRec                        timeBase;                    /*MIDIIDRec for time base*/
  139.     short                            numConnects;                /*number of connections*/
  140.     MIDIIDRec                        cList[1];                    /*ARRAY [1..numConnects] of MIDIIDRec*/
  141. };
  142. typedef struct MIDIPortInfo MIDIPortInfo;
  143.  
  144. typedef MIDIPortInfo *MIDIPortInfoPtr, **MIDIPortInfoHdl, **MIDIPortInfoHandle;
  145.  
  146. struct MIDIPortParams {
  147.     OSType                            portID;                        /*ID of port, unique within client*/
  148.     short                            portType;                    /*Type of port - input, output, time, etc.*/
  149.     short                            timeBase;                    /*refnum of time base, 0 if none*/
  150.     long                            offsetTime;                    /*offset for current time stamps*/
  151.     Ptr                                readHook;                    /*routine to call when input data is valid*/
  152.     long                            refCon;                        /*refcon for port (for client use)*/
  153.     MIDIClkInfo                        initClock;                    /*initial settings for a time base*/
  154.     Str255                            name;                        /*name of the port, This is a real live string, not a ptr.*/
  155. };
  156. typedef struct MIDIPortParams MIDIPortParams;
  157.  
  158. typedef MIDIPortParams *MIDIPortParamsPtr;
  159.  
  160. struct MIDIIDList {
  161.     short                            numIDs;
  162.     OSType                            list[1];
  163. };
  164. typedef struct MIDIIDList MIDIIDList;
  165.  
  166. typedef MIDIIDList *MIDIIDListPtr, **MIDIIDListHdl, **MIDIIDListHandle;
  167.  
  168. /* 
  169.     
  170.          Prototype Declarations for readHook and timeProc
  171.         
  172.          extern pascal short myReadHook(MIDIPacketPtr myPacket, long myRefCon);
  173.          extern pascal void myTimeProc(long curTime, long myRefCon);
  174.         
  175.          MIDI Manager Routines
  176. */
  177. extern pascal NumVersion MIDIVersion(void)
  178.  FOURWORDINLINE(0x203C, 0x0000, 4, 0xA800);
  179. extern pascal OSErr MIDISignIn(OSType clientID, long refCon, Handle icon, ConstStr255Param name)
  180.  FOURWORDINLINE(0x203C, 0x0004, 4, 0xA800);
  181. extern pascal void MIDISignOut(OSType clientID)
  182.  FOURWORDINLINE(0x203C, 0x0008, 4, 0xA800);
  183. extern pascal MIDIIDListHandle MIDIGetClients(void)
  184.  FOURWORDINLINE(0x203C, 0x000C, 4, 0xA800);
  185. extern pascal void MIDIGetClientName(OSType clientID, Str255 name)
  186.  FOURWORDINLINE(0x203C, 0x0010, 4, 0xA800);
  187. extern pascal void MIDISetClientName(OSType clientID, ConstStr255Param name)
  188.  FOURWORDINLINE(0x203C, 0x0014, 4, 0xA800);
  189. extern pascal MIDIIDListHandle MIDIGetPorts(OSType clientID)
  190.  FOURWORDINLINE(0x203C, 0x0018, 4, 0xA800);
  191. extern pascal OSErr MIDIAddPort(OSType clientID, short BufSize, short *refnum, MIDIPortParamsPtr init)
  192.  FOURWORDINLINE(0x203C, 0x001C, 4, 0xA800);
  193. extern pascal MIDIPortInfoHandle MIDIGetPortInfo(OSType clientID, OSType portID)
  194.  FOURWORDINLINE(0x203C, 0x0020, 4, 0xA800);
  195. extern pascal OSErr MIDIConnectData(OSType srcClID, OSType srcPortID, OSType dstClID, OSType dstPortID)
  196.  FOURWORDINLINE(0x203C, 0x0024, 4, 0xA800);
  197. extern pascal OSErr MIDIUnConnectData(OSType srcClID, OSType srcPortID, OSType dstClID, OSType dstPortID)
  198.  FOURWORDINLINE(0x203C, 0x0028, 4, 0xA800);
  199. extern pascal OSErr MIDIConnectTime(OSType srcClID, OSType srcPortID, OSType dstClID, OSType dstPortID)
  200.  FOURWORDINLINE(0x203C, 0x002C, 4, 0xA800);
  201. extern pascal OSErr MIDIUnConnectTime(OSType srcClID, OSType srcPortID, OSType dstClID, OSType dstPortID)
  202.  FOURWORDINLINE(0x203C, 0x0030, 4, 0xA800);
  203. extern pascal void MIDIFlush(short refnum)
  204.  FOURWORDINLINE(0x203C, 0x0034, 4, 0xA800);
  205. extern pascal ProcPtr MIDIGetReadHook(short refnum)
  206.  FOURWORDINLINE(0x203C, 0x0038, 4, 0xA800);
  207. extern pascal void MIDISetReadHook(short refnum, ProcPtr hook)
  208.  FOURWORDINLINE(0x203C, 0x003C, 4, 0xA800);
  209. extern pascal void MIDIGetPortName(OSType clientID, OSType portID, Str255 name)
  210.  FOURWORDINLINE(0x203C, 0x0040, 4, 0xA800);
  211. extern pascal void MIDISetPortName(OSType clientID, OSType portID, ConstStr255Param name)
  212.  FOURWORDINLINE(0x203C, 0x0044, 4, 0xA800);
  213. extern pascal void MIDIWakeUp(short refnum, long time, long period, ProcPtr timeProc)
  214.  FOURWORDINLINE(0x203C, 0x0048, 4, 0xA800);
  215. extern pascal void MIDIRemovePort(short refnum)
  216.  FOURWORDINLINE(0x203C, 0x004C, 4, 0xA800);
  217. extern pascal short MIDIGetSync(short refnum)
  218.  FOURWORDINLINE(0x203C, 0x0050, 4, 0xA800);
  219. extern pascal void MIDISetSync(short refnum, short sync)
  220.  FOURWORDINLINE(0x203C, 0x0054, 4, 0xA800);
  221. extern pascal long MIDIGetCurTime(short refnum)
  222.  FOURWORDINLINE(0x203C, 0x0058, 4, 0xA800);
  223. extern pascal void MIDISetCurTime(short refnum, long time)
  224.  FOURWORDINLINE(0x203C, 0x005C, 4, 0xA800);
  225. extern pascal void MIDIStartTime(short refnum)
  226.  FOURWORDINLINE(0x203C, 0x0060, 4, 0xA800);
  227. extern pascal void MIDIStopTime(short refnum)
  228.  FOURWORDINLINE(0x203C, 0x0064, 4, 0xA800);
  229. extern pascal void MIDIPoll(short refnum, long offsetTime)
  230.  FOURWORDINLINE(0x203C, 0x0068, 4, 0xA800);
  231. extern pascal OSErr MIDIWritePacket(short refnum, MIDIPacketPtr packet)
  232.  FOURWORDINLINE(0x203C, 0x006C, 4, 0xA800);
  233. extern pascal Boolean MIDIWorldChanged(OSType clientID)
  234.  FOURWORDINLINE(0x203C, 0x0070, 4, 0xA800);
  235. extern pascal long MIDIGetOffsetTime(short refnum)
  236.  FOURWORDINLINE(0x203C, 0x0074, 4, 0xA800);
  237. extern pascal void MIDISetOffsetTime(short refnum, long offsetTime)
  238.  FOURWORDINLINE(0x203C, 0x0078, 4, 0xA800);
  239. extern pascal long MIDIConvertTime(short srcFormat, short dstFormat, long time)
  240.  FOURWORDINLINE(0x203C, 0x007C, 4, 0xA800);
  241. extern pascal long MIDIGetRefCon(short refnum)
  242.  FOURWORDINLINE(0x203C, 0x0080, 4, 0xA800);
  243. extern pascal void MIDISetRefCon(short refnum, long refCon)
  244.  FOURWORDINLINE(0x203C, 0x0084, 4, 0xA800);
  245. extern pascal long MIDIGetClRefCon(OSType clientID)
  246.  FOURWORDINLINE(0x203C, 0x0088, 4, 0xA800);
  247. extern pascal void MIDISetClRefCon(OSType clientID, long refCon)
  248.  FOURWORDINLINE(0x203C, 0x008C, 4, 0xA800);
  249. extern pascal short MIDIGetTCFormat(short refnum)
  250.  FOURWORDINLINE(0x203C, 0x0090, 4, 0xA800);
  251. extern pascal void MIDISetTCFormat(short refnum, short format)
  252.  FOURWORDINLINE(0x203C, 0x0094, 4, 0xA800);
  253. extern pascal void MIDISetRunRate(short refnum, short rate, long time)
  254.  FOURWORDINLINE(0x203C, 0x0098, 4, 0xA800);
  255. extern pascal Handle MIDIGetClientIcon(OSType clientID)
  256.  FOURWORDINLINE(0x203C, 0x009C, 4, 0xA800);
  257. extern pascal long SndDispVersion(short toolnum)
  258.  FOURWORDINLINE(0x203C, 0x0000, 0x0000, 0xA800);
  259.  
  260. #ifdef __CFM68K__
  261. #pragma lib_export off
  262. #endif
  263.  
  264. #if GENERATINGPOWERPC
  265. #pragma options align=reset
  266. #endif
  267.  
  268. #ifdef __cplusplus
  269. }
  270. #endif
  271.  
  272. #endif /* __MIDI__ */
  273.